package com.horse.utils;

public class StopWatch {
	private long startTime = 0;
	private long stopTime = 0;
	private boolean running = false;

	public void start() {
		this.startTime = System.currentTimeMillis();
		this.running = true;
	}

	public void stop() {
		this.stopTime = System.currentTimeMillis();
		this.running = false;
	}

	// elaspsed time in milliseconds
	public long getElapsedTime() {
		long elapsed;
		if (running) {
			elapsed = (System.currentTimeMillis() - startTime);
			elapsed = elapsed / 100;
		} else {
			elapsed = (stopTime - startTime);
		}
		return elapsed;
	}

	public String getElapsedTimeAsString() {
		String time = "";
		long timeInMSec;
		int sec;
		int decimalSec;
		if (running) {
			timeInMSec = (System.currentTimeMillis() - startTime);

		} else {
			timeInMSec = (stopTime - startTime);
		}
		sec = (int) (10 - timeInMSec / 1000);
		return ""+sec;
	}
	
	public String getTime()
	{
		return getElapsedTimeAsString()+"."+getElapsedTimeSecs();
	}

	// elaspsed time in seconds
	public String getElapsedTimeSecs() {
		String time="";
		long elapsed;
		if (running) {
			elapsed = System.currentTimeMillis() - startTime;
		} else {
			elapsed = stopTime - startTime;
		}
		int tenth=10-(int)((elapsed%1000)/100);
		return time+tenth;
	}
}
